﻿using System;
using System.Windows.Forms;

namespace Anheledir.XmlDialogEditor {
  public partial class wizardTrigger : Form {
    string f = string.Empty;

    public wizardTrigger() {
      InitializeComponent();
    }

    public wizardTrigger(string s) {
      InitializeComponent();
      f = s;
    }

    public string getText() {
      return textBox1.Text;
    }

    private void comboBox1_Leave( object sender, EventArgs e ) {
      if ( itemType.Text == "ATTACHMENT" ) {
        labelAttachmentName.Visible = true;
        labelAttachmentType.Visible = true;
        attachmentName.Visible = true;
        attachmentType.Visible = true;
        conditionEquipped.Visible = false;
        itemName.Visible = false;
        labelItemName.Visible = false;
        questholderName.Visible = false;
        questholderObjectives.Visible = false;
        labelQuestholderName.Visible = false;
        labelQuestholderObjectives.Visible = false;
      } else if ( itemType.Text == "XmlQuestToken" ) {
        labelAttachmentName.Visible = false;
        labelAttachmentType.Visible = false;
        attachmentName.Visible = false;
        attachmentType.Visible = false;
        conditionEquipped.Visible = false;
        itemName.Visible = false;
        labelItemName.Visible = false;
        questholderName.Visible = true;
        questholderObjectives.Visible = true;
        labelQuestholderName.Visible = true;
        labelQuestholderObjectives.Visible = true;
      } else {
        labelAttachmentName.Visible = false;
        labelAttachmentType.Visible = false;
        attachmentName.Visible = false;
        attachmentType.Visible = false;
        conditionEquipped.Visible = true;
        itemName.Visible = true;
        labelItemName.Visible = true;
        questholderName.Visible = false;
        questholderObjectives.Visible = false;
        labelQuestholderName.Visible = false;
        labelQuestholderObjectives.Visible = false;
      }
    }

    private void textBox1_TextChanged( object sender, EventArgs e ) {
      if ( textBox1.Text == string.Empty ) {
        button1.Enabled = true;
        button2.Enabled = false;
        button3.Enabled = false;
      } else {
        button1.Enabled = false;
        button2.Enabled = true;
        button3.Enabled = true;
      }
    }

    private void button1_Click( object sender, EventArgs e ) {
      if ( itemType.Text == "ATTACHMENT" ) {
        textBox1.Text += string.Format( "ATTACHMENT,{0},{1}", attachmentName.Text, attachmentType.Text );
      } else if ( itemType.Text == "XmlQuestToken" ) {
        string qhois = "";
        foreach ( int qhoi in questholderObjectives.CheckedIndices ) {
          qhois += "," + (qhoi+1).ToString();
        }
        textBox1.Text += string.Format( "{0}{1}", questholderName.Text, qhois );
      } else {
        if ( itemType.Text == string.Empty ) {
                  textBox1.Text += string.Format("{0}", itemName.Text);
        } else {
          textBox1.Text += string.Format( "{0}{1}", itemName.Text, "," + itemType.Text + ( conditionEquipped.Checked ? ",EQUIPPED" : "" ) );
        }
      }
    }

    private void button2_Click( object sender, EventArgs e ) {
      textBox1.Text += " & ";
      button1_Click( sender, e );
    }

    private void button3_Click( object sender, EventArgs e ) {
      textBox1.Text += " | ";
      button1_Click( sender, e );
    }

    private void wizardTrigger_Load( object sender, EventArgs e ) {
      this.Text = languages.NoTrigOnCarriedAssistent;
      groupBox1.Text = languages.NewCondition;
      labelItemType.Text = languages.ItemType;
      button1.Text = languages.AddCondition;
      button2.Text = languages.AND;
      button3.Text = languages.OR;
      okButton.Text = languages.OK;
      cancelButton.Text = languages.Cancel;
      labelQuestholderObjectives.Text = languages.Objectives;
      labelItemName.Text = languages.ItemName;
      labelQuestholderName.Text = languages.QuestholderName;
      labelAttachmentName.Text = languages.AttachmentName;
      labelAttachmentType.Text = languages.AttachmentType;
      conditionEquipped.Text = languages.Equipped;

      questholderObjectives.Items.Clear();
      for ( int i = 1; i <= 5; i++ ) {
        questholderObjectives.Items.Add( languages.Objective + " " + i.ToString() );
      }

      if ( f != string.Empty ) {
        textBox1.Text = f;
      }
      foreach ( XmlSpawnerLibrary.XmlAttachment a in XmlSpawnerLibrary.XmlAttachments() ) {
        attachmentType.Items.Add( a.Name );
      }
      comboBox1_Leave( sender, e );
    }
  }
}
